<template>
  <div>
    <el-form :model="ruleForm"  ref="ruleForm" :label-position="labelPosition"
             :class="isEdit?'':'formItem'">
      <el-card class="box-card" shadow="never">
        <div slot="header" class="header-card">
          <span class="header-card-title">邮寄信息</span>
        </div>

        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="邮寄地址:" prop="applyReason"
                          :rules="!isEdit? [] : rules.applyReason ">
              <el-input v-if="isEdit" type="textarea" v-model="ruleForm.applyReason" placeholder="请输入申请原因"
                        :rows="4" maxlength="500"  show-word-limit/>
              <span v-else>{{ ruleForm.applyReason }}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'postMessage',//邮寄信息
  props: {
    value: {
      type: Object,
      default: () => {
      }
    },
    state: {
      type: String,
      default: "",
    },
  },
  computed: {
    ruleForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            if (value) {
              that.handleClearValidate(key)
            }
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    labelPosition() {
      if (this.state === 'write') {
        return 'top'
      } else {
        return 'right'
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool
    }
  },
  watch: {},
  data() {
    return {
      rules: {
        applyReason: [
          {required: true, message: '请输入处置原因', trigger: 'blur'}
        ]
      }
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    valid() {
      return new Promise((resolve) => {
        this.$refs.ruleForm.validate((valid) => {
          resolve(valid);
        });
      });
    },
    handleClearValidate(str) {
      this.$refs.ruleForm.clearValidate(str);
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/formScss.scss";
</style>


